<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 3] 3.4 The Netscape Alternative</TITLE>
<META NAME="author" CONTENT="Pat Niemeyer and Josh Peck">
<META NAME="date" CONTENT="Tue Jul 22 18:49:33 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Exploring Java">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Exploring Java" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch03_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 3<br>Tools of the Trade</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch03_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="EXJ-CH-3-SECT-4">3.4 The Netscape Alternative</A></h2>

<P CLASS=para>
If the JDK is not available for your platform, but you have
access to a Java-enabled version of Netscape Navigator, you can take
advantage of a special Netscape switch to compile and run Java
applications. The <tt CLASS=literal>-java</tt> switch provides direct
access to Netscape's implementation of the Java run-time system
and supports the same command-line options as Sun's
<i CLASS=command>java</i> interpreter.  Here's the general syntax for
using the <tt CLASS=literal>-java</tt> switch:

<DIV CLASS=screen>
<P>
<PRE>
% netscape -java [<tt CLASS=replaceable><i>interpreter options</i></tt>] <tt CLASS=replaceable><i>class name</i></tt> [<tt CLASS=replaceable><i>program arguments</i></tt>]
</PRE>
</DIV>

<P CLASS=para>
Before you can use Netscape's <tt CLASS=literal>-java</tt> switch,
you have to download the JDK; you need the
<i CLASS=filename>classes.zip</i> file that is part of the
JDK distribution.  After you have unpacked the
distribution, set the <tt CLASS=literal>CLASSPATH</tt> environment
variable to point to both Netscape's class archive and the
<i CLASS=filename>classes.zip</i> file from the JDK:

<DIV CLASS=screen>
<P>
<PRE>
CLASSPATH=/usr/lib/java/classes.zip:/home/vicky/.netscape/moz2_0.zip:.
</PRE>
</DIV>

<P CLASS=para>
Now you can compile a <i CLASS=filename>.java</i> file using
Netscape's <tt CLASS=literal>-java</tt> switch as follows:

<DIV CLASS=screen>
<P>
<PRE>
% netscape -java sun.tools.javac.Main <tt CLASS=replaceable><i>source file</i></tt>
</PRE>
</DIV>

<P CLASS=para>
In this case, you are actually using the <tt CLASS=literal>-java</tt>
switch to run the Java compiler, <i CLASS=command>javac</i>, and
supplying the source file as an argument to the compiler.
Recall that <i CLASS=command>javac</i> is itself a Java program,
which is why you can run it using the <tt CLASS=literal>-java</tt>
switch.  The above command produces a class file and stores it
in the same directory as the source file.

<P CLASS=para>
After you have compiled a Java application with Netscape, you can
use Netscape to run it.  You can use the <tt CLASS=literal>-java</tt>
switch to run nongraphical Java applications.  In other words, you can
run any application that doesn't use AWT.  You
can't use the <tt CLASS=literal>-java</tt> switch to run applications
that use AWT because Netscape has its own toolkit
that employs Netscape native components.  However, you can use the
<tt CLASS=literal>-java</tt> switch to compile applets (and applications)
that use AWT.  As always, you can display these
applets using Netscape as a Web browser.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch03_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch03_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>The Java Compiler</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>The Applet Tag</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
